#include "StatusWidget.h"
#include "ui_StatusWidget.h"

StatusWidget::StatusWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::StatusWidget)
{
    ui->setupUi(this);
    recvCount = 0;
    sendCount = 0;
    connect(ui->pushButtonClear,SIGNAL(clicked()),this,SLOT(slotPushButton()));
}

StatusWidget::~StatusWidget()
{
    delete ui;
}

void StatusWidget::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

 void StatusWidget::slotPushButton()
 {
     recvCount = 0;
     sendCount = 0;
     slotAddCount(0,1);
     slotAddCount(0,0);
 }
void StatusWidget::slotMessage(QString str)
{
    ui->labelStatus->setText(str);
}

void StatusWidget::slotAddCount(int size, int flag)
{
    if (size < 0)
        return;

    if (flag == 1)
    {
        recvCount += size;
        QString str = QString(tr("Recv:%1")).arg(recvCount);
        ui->labelRecv->setText(str);
    }
    else if (flag == 0)
    {
        sendCount += size;
        QString str = QString(tr("Send:%1")).arg(sendCount);
        ui->labelSend->setText(str);
    }

}
